﻿<!--_meta 作为公共模版分离出去-->
<#include "../../../common/_meta.ftl">
<!--/meta 作为公共模版分离出去-->

<title>新建网站角色组 - 管理员组管理 - H-ui.admin v3.1</title>
<meta name="keywords" content="H-ui.admin v3.1,H-ui网站后台模版,后台模版下载,后台管理系统模版,HTML后台模版下载">
<meta name="description" content="H-ui.admin v3.1，是一款由国人开发的轻量级扁平化网站后台模板，完全免费开源的网站后台管理系统模版，适合中小型CMS后台系统。">
</head>
<body>
<article class="page-container">
	<form action="" method="" class="form form-horizontal" id="form-admin-rolegroup-add">
		<input type="hidden" name="_method" value="put" />
		<input type="hidden" value="" class="from-data" id="groleid" name="groleid">
		<input type="hidden" value="" class="from-data" id="parentid" name="parentid">
		<input type="hidden" value="" class="from-data" id="parentids" name="parentids">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色组名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text from-data" value="" placeholder="" id="grolename" name="grolename">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">描述：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text from-data" value="" placeholder="" id="info" name="info" maxlength="100">
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<button type="submit" class="btn btn-success radius" id="admin-rolegroup-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
			</div>
		</div>
	</form>
</article>

<!--_footer 作为公共模版分离出去-->
<#include "../../../common/_footer.ftl">
<!--/_footer 作为公共模版分离出去-->
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="${springMacroRequestContext.contextPath}/static/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="${springMacroRequestContext.contextPath}/static/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="${springMacroRequestContext.contextPath}/static/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
let url = contextPath+"/adminApi/rolegroup/";
$(function(){
	let groleid = '${groleid}';
	let parentid = '${parentid}';
	let isHave = (groleid != null && groleid != '');
	let RequestType = 'post';
	if(isHave){
		RequestType = 'put';

		$.ajax({
			url: url+groleid,
			type: "GET",
			dataType:"json",
			cache:false,
			async:false,
			success:function(data){
				if (data.code == 200){
					$('#groleid').val(data.data.groleid);
					$('#parentid').val(data.data.parentid);
					$('#parentids').val(data.data.parentids);
					$('#grolename').val(data.data.grolename);
					$('#info').val(data.data.info);
					// TODO 遍历循环赋值
					// $('.from-data').each(function () {
					// 	console.dir(data);
					// 	let keyName = $(this).attr("name");
					// 	$('#'+keyName).val("data.data."+keyName);
					// });
				}
			},
			error:function(data){
				layer.msg('查询异常!',{icon:2,time:1000});
			}
		});
	}else{
		$('#parentid').val(parentid);
	}


	$("#form-admin-rolegroup-add").validate({
		rules:{
			grolename:{
				required:true,
			},
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
				url: url,
				type: RequestType,
				success: function(data) {
					if (data.code == 200){
						layer.msg('保存成功!',{icon:1,time:1000});
						window.parent.reload();
						let index = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
					}else{
						layer.msg('保存错误!',{icon:2,time:1000});
					}
				},
				error: function(data){
					layer.msg('数据提交异常!',{icon:2,time:1000});
				}
			});
		}
	});
});
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>